require 'rubygems'
require 'ferret'


class SearcherController < ApplicationController
  
  
  def search
    @query = nil
    @entrys = []
    
    if !params[:query].nil? then
      
      idx = Ferret::Index::IndexReader.new INDEX_PATH
      idx_searcher = Ferret::Search::Searcher.new idx 
      query_parser = Ferret::QueryParser.new
      
      @query = query_parser.parse(params[:query])
      
      idx_searcher.search_each(@query, :limit => 300) do |doc_id, score|
        doc = idx.get_document doc_id 
        doc.load
        @entrys << doc
      end
      
      idx_searcher.close
      idx.close
    end
    
  end
end
